package com.ruoyi.web.controller.clothing;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.clothing.domain.SysGoods;
import com.ruoyi.clothing.service.ISysGoodsService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 商品Controller
 *
 * @author weh
 * @date 2024-01-18
 */
@RestController
@RequestMapping("/clothing/goods")
public class SysGoodsController extends BaseController {
    @Autowired
    private ISysGoodsService sysGoodsService;

    /**
     * 查询商品列表
     */
//    @PreAuthorize("@ss.hasPermi('clothing:goods:list')")
    @GetMapping("/list")
    public TableDataInfo list(SysGoods sysGoods) {
        startPage();
        List<SysGoods> list = sysGoodsService.selectSysGoodsList(sysGoods);
        return getDataTable(list);
    }

    /**
     * 导出商品列表
     */
//    @PreAuthorize("@ss.hasPermi('clothing:goods:export')")
    @Log(title = "商品", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, SysGoods sysGoods) {
        List<SysGoods> list = sysGoodsService.selectSysGoodsList(sysGoods);
        ExcelUtil<SysGoods> util = new ExcelUtil<SysGoods>(SysGoods.class);
        util.exportExcel(response, list, "商品数据");
    }

    /**
     * 获取商品详细信息
     */
//    @PreAuthorize("@ss.hasPermi('clothing:goods:query')")
    @GetMapping(value = "/id")
    public SysGoods getInfo(@RequestParam Integer id) {
        return sysGoodsService.selectSysGoodsById(id);
    }

    /**
     * 新增商品
     */
//    @PreAuthorize("@ss.hasPermi('clothing:goods:add')")
    @Log(title = "商品", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody SysGoods sysGoods) {
        return toAjax(sysGoodsService.insertSysGoods(sysGoods));
    }

    /**
     * 修改商品
     */
//    @PreAuthorize("@ss.hasPermi('clothing:goods:edit')")
    @Log(title = "商品", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody SysGoods sysGoods) {
        return toAjax(sysGoodsService.updateSysGoods(sysGoods));
    }

    /**
     * 删除商品
     */
//    @PreAuthorize("@ss.hasPermi('clothing:goods:remove')")
    @Log(title = "商品", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Integer[] ids) {
        return toAjax(sysGoodsService.deleteSysGoodsByIds(ids));
    }

    /**
     * 获取热门商品列表
     *
     * @return
     */
    @GetMapping("/hotList")
    public List<SysGoods> getListByIsHot() {
        List<SysGoods> goodsListHot = sysGoodsService.getGoodsListHot();
        return goodsListHot;
    }

//    /**
//     * 获取男士商品列表
//     * @return
//     */
//    @GetMapping("/selectManListByType/{styleid}")
//    public List<SysGoods> getManListById(@PathVariable(value = "styleid") Integer style_detail){
//        return sysGoodsService.getManListById(style_detail);
//    }

//    /**
//     * 获取女士商品列表
//     * @return
//     */
//    @GetMapping("/selectWomanListByType/{styleid}")
//    public List<SysGoods> getWomanList(){
//        List<SysGoods> womanList = sysGoodsService.getWomanList();
//        return womanList;
//    }


    /**
     * 根据款式详情查询男士相关款式商品列表
     *
     * @param style_detail
     * @return
     */
    @GetMapping("/selectManListByType/{styleid}")
    public List<SysGoods> getManListById(@PathVariable(value = "styleid") Integer style_detail) {
        return sysGoodsService.getManListById(style_detail);
    }

    /**
     * 根据款式详情查询女士相关款式商品列表
     *
     * @param style_detail
     * @return
     */
    @GetMapping("/selectWomanListByType/{styleid}")
    public List<SysGoods> getWomanListById(@PathVariable(value = "styleid") Integer style_detail) {
        return sysGoodsService.getWomanListById(style_detail);
    }

    /**
     * 模糊查询
     *
     * @param key
     * @return
     */
    @GetMapping("/fuzzyQuery")
    public List<SysGoods> fuzzyQuery(@RequestParam String key) {
        return sysGoodsService.fuzzyQuery(key);
    }
}
